﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Super_Wall_Breaker.Sources.GameEngine;
using System;

namespace Super_Wall_Breaker.Sources.GameElements.Bats
{
    /// <summary>
    /// Class bat
    /// </summary>
    public class Bat : MovableSprite
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="Bat"/> class.
        /// </summary>
        public Bat() { }

        /// <summary>
        /// Initializes a new instance of the <see cref="Bat"/> class.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="speed">The speed.</param>
        /// <param name="sourceRectangle">The source rectangle in the spritesheet.</param>
        public Bat(Vector2 position, Vector2 speed,Rectangle? sourceRectangle)
            : base(position, speed,sourceRectangle) 
        { }

        /// <summary>
        /// Updates the bat.
        /// </summary>
        /// <param name="gameTime">A snapshot of the game time.</param>
        public override void Update(GameTime gameTime)
        {
            float nextX = this.Position.X + Origin.X + this.Speed.X * gameTime.ElapsedGameTime.Milliseconds;
            GlobalConfiguration config = GlobalConfiguration.Configuration;

            int batWidth = this.Texture.Width;

            if (this.SourceRectangle != null)
            {
                batWidth = this.SourceRectangle.Value.Width;
            }

            int leftLimite = 0;
            int rightLimite = config.ScreenWidth - batWidth;

            if (this.Rotation == MathHelper.Pi)
            {
                leftLimite = batWidth;
                rightLimite = config.ScreenWidth;
            }

            if (nextX > leftLimite && nextX < rightLimite)
            {
                base.Update(gameTime);
            }
        }
    }
}
